package com.example.saiweisi.service.impl.sysTemAdminService;

import com.example.saiweisi.controller.request.DeskRequest;
import com.example.saiweisi.mapper.systemAdminMapper.DeskMapper;
import com.example.saiweisi.model.Desk;
import com.example.saiweisi.service.interf.IdeskService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeskService implements IdeskService {
    @Autowired
    DeskMapper chefAdminMapper;

    @Override
    public PageInfo<Desk> page(DeskRequest chefAdminRequest) {
        PageHelper.startPage(chefAdminRequest.getPageNum(), chefAdminRequest.getPageSize());
        List<Desk> userList = chefAdminMapper.page(chefAdminRequest);
        return new PageInfo<>(userList);
    }

    @Override
    public void add(Desk chefAdmin) {
        chefAdminMapper.insertSelective(chefAdmin);
    }

//    @Override
//    public void addchefadmin(ChefAdmin chefAdmin) {
//        //遍历数据库，将最大的 num加一 赋值给新用户，来达到生成唯一标识符的目的
//        int s=1;
//        List<ChefAdmin> list=chefAdminMapper.getall();
//        for (ChefAdmin a:list
//        ) {
//            if(Integer.parseInt(a.getChefAdminNum().substring(1))>s){
//                s=Integer.parseInt(a.getChefAdminNum().substring(1));
//            }
//        }
////        String b=IdUtil.fastSimpleUUID();
////        Integer a=Integer.parseInt(b);
//        chefAdmin.setChefAdminNum("300"+Integer.toString(s+1));
//        chefAdminMapper.addchefadmin(chefAdmin);
//    }
//
    @Override
    public void delete(Integer chefAdminId) {
        Desk desk = new Desk();
        desk.setDeskId(chefAdminId);
        desk.setIsDelete(1);
        chefAdminMapper.updateByPrimaryKeySelective(desk);
    }

    @Override
    public Desk getById(Integer chefAdminId) {
        return chefAdminMapper.selectByPrimaryKey(Long.valueOf(chefAdminId));
    }

    @Override
    public void update(Desk chefAdmin) {
        chefAdminMapper.updateByPrimaryKeySelective(chefAdmin);
    }

    @Override
    public void deletes(List<Integer> chefAdminIds) {
        for (Integer a:chefAdminIds
             ) {
            Desk desk = new Desk();
            desk.setDeskId(a);
            desk.setIsDelete(1);
            chefAdminMapper.updateByPrimaryKeySelective(desk);
        }
    }
//
//    @Override
//    public void resetPassword(Integer chefAdminId) {
//        chefAdminMapper.resetPassword(chefAdminId);
//    }
}
